package com.hnyfkj.jyindustry.biz.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hnyfkj.jyindustry.biz.item.dao.BarItemDao;
import com.hnyfkj.jyindustry.biz.item.dto.BarItemInsertDto;
import com.hnyfkj.jyindustry.biz.item.dto.BarItemQueryDto;
import com.hnyfkj.jyindustry.biz.item.dto.BarItemUpdateDto;
import com.hnyfkj.jyindustry.biz.item.entity.BarItem;
import com.hnyfkj.jyindustry.biz.item.service.BarItemService;
import com.hnyfkj.jyindustry.biz.item.vo.BarItemVo;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import com.hnyfkj.jyindustry.common.utils.ShiroUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service("barItemService")
public class BarItemServiceImpl extends ServiceImpl<BarItemDao, BarItem> implements BarItemService {


    @Autowired
    private BarItemDao barItemDao;



    @Override
    public PageReturnDto<BarItemVo> queryPage(BarItemQueryDto queryDto) {
        PageInfo<BarItemVo> page =
                PageHelper.startPage(queryDto.getPage(), queryDto.getLimit()).doSelectPageInfo(() -> barItemDao.selectListByQuery(queryDto));
        return PageReturnDto.pageOf(page);
    }

    @Override
    public int insert(BarItemInsertDto barItemInsertDto) {
        final BarItem barItem = new BarItem();
        BeanUtils.copyProperties(barItemInsertDto, barItem);
        return barItemDao.insert(barItem);
    }

    @Override
    public int update(BarItemUpdateDto barItemUpdateDto) {
        final BarItem barItem = new BarItem();
        BeanUtils.copyProperties(barItemUpdateDto, barItem);
        return barItemDao.updateById(barItem);
    }

    @Override
    public int delete(String ids) {
        String[] id = ids.split(",");
        return barItemDao.deleteBatchIds(Arrays.asList(id));
    }

    @Override
    public List<BarItem> listNoPage() {
        String shipId = ShiroUtils.getSessionAttribute("memberId").toString();
        return barItemDao.selectList(new QueryWrapper<BarItem>().eq("shop_id",shipId));
    }
}